#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

// zdl:: 还是需要仔细地读题
const int N = 1e5 + 10;
struct node
{
    int p;
    string s;
}a[N];
int n, m;
int main()
{
    cin >> n >> m;
    // 需要进行取模的操作时就需要将数组的下标从0开始
    for (int i = 0; i < n; i++) cin >> a[i].p >> a[i].s;
    int pos = 0;
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        if (a[pos].p == x)
        {
            pos = (pos - y + n) % n;
        }
        else pos = (pos + y + n) % n;
    }


    cout << a[pos].s << endl;
    return 0;
}